package com.front.managementfront.driver.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.front.managementfront.utils.CustomPageUtils;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.common.utils.SnowFlakeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.front.managementfront.driver.service.IHktsDriverDetailService;
import com.front.managementfront.driver.entity.HktsDriverDetail;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author yck
 * @since 2021-08-06
 */
@RestController
@RequestMapping("/front/hktsDriverDetail")
public class HktsDriverDetailController {
    private final Logger logger = LoggerFactory.getLogger(HktsDriverDetailController.class);

    @Autowired
    public IHktsDriverDetailService iHktsDriverDetailService;


    /**
     * 分页查询数据
     *
     * @param page             分页信息
     * @param hktsDriverDetail 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsDriverDetailPageList")
    public Result<Object> getHontUserList(Page<HktsDriverDetail> page, HktsDriverDetail hktsDriverDetail) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsDriverDetailService.selectPage(page, hktsDriverDetail)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsDriverDetail 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsDriverDetailSave")
    public Result<Object> hktsDriverDetailSave(HktsDriverDetail hktsDriverDetail) {
        iHktsDriverDetailService.saveOrUpdate(hktsDriverDetail);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsDriverDetailGetById")
    public Result<Object> hktsDriverDetailGetById(String id) {
        HktsDriverDetail byId = iHktsDriverDetailService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsDriverDetailDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsDriverDetailService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsDriverDetailBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsDriverDetailService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /**
     * 保存和修改公用的
     *
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/addDriverDetail")
    public Result<Object> addDriverDetail(@RequestParam("driverId") String driverId,@RequestParam("applauseRate") BigDecimal applauseRate,@RequestParam("tradeCount") Integer tradeCount) {
        QueryWrapper<HktsDriverDetail> query = Wrappers.query();
        query.lambda().eq(HktsDriverDetail::getDriverId,driverId);
        HktsDriverDetail hktsDriverDetail=iHktsDriverDetailService.getOne(query);
        if(hktsDriverDetail==null){
            hktsDriverDetail=new HktsDriverDetail();
            hktsDriverDetail.setId(String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId()));
            hktsDriverDetail.setDriverId(driverId);
        }
        hktsDriverDetail.setApplauseRate(applauseRate);
        hktsDriverDetail.setTradeCount(tradeCount);
        iHktsDriverDetailService.saveOrUpdate(hktsDriverDetail);
        return ResultUtil.success("保存成功");
    }
   /** 功能描述:
   *根据用户ids查询
   * @return:
   * @Author: 杨春科
   * @Date: 2021-08-23 14:52
   * @Description //TODO
   */

}
